#include "AppDelegate.h"

#include "cocos2d.h"
#include "GameLaunchScene.h"
#include "PTScene.h"
#include "ThemeScene.h"
#include "MusicController.h"
#include "GameData.h"

USING_NS_CC;

MusicController * s_gController;

AppDelegate::AppDelegate()
{

}

AppDelegate::~AppDelegate()
{
}

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    CCEGLView * view = CCEGLView::sharedOpenGLView();
    view->setDesignResolutionSize(480,320,kResolutionShowAll);
    pDirector->setOpenGLView(view);

    // turn on display FPS
    pDirector->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    CCScene *pScene = GameLaunchScene::scene();
    //CCScene *pScene = ThemeScene::scene();
    //CCScene *pScene = PTScene::scene();
    // run
    pDirector->runWithScene(pScene);

    s_gController = MusicController::getInstance();
    s_gController->init();
    s_gController->preloadMusic(GameData::getInstance()->getMusicPath());
    s_gController->startMusic(GameData::getInstance()->getMusicPath(),true);
    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->pause();

    //pause music android effect
    s_gController->pauseMusic();
     //MusicController::pauseEffect();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->resume();
    
    // resume music android effect
    s_gController->resumeMusic();
   // MusicController::resumeEffect();
}
